<script setup lang="ts">
import * as z from "zod";
import { Plus } from "@element-plus/icons-vue";
import { useUserStore } from "@/stores/userStore";
const schema = z.object({
  name: z.string().min(2, "Too short"),
  email: z.string().email("Invalid email"),
});
const userStore = useUserStore();
const open = ref(false);

type Schema = z.output<typeof schema>;

const state = reactive<Partial<Schema>>({
  name: undefined,
  email: undefined,
});

const toast = useToast();
async function onSubmit() {
  toast.add({
    title: "Success",
    description: `New customer ${state.name} added`,
    color: "success",
  });
  open.value = false;
}
</script>

<template>
  <el-button :icon="Plus" @click="open = true">New customer</el-button>
  <el-dialog v-model="open" title="New customer" @close="open = false">
    <el-form :model="state" label-width="auto" class="space-y-4" @submit="onSubmit">
      <el-form-item label="Name" name="name">
        <el-input v-model="state.name" placeholder="John Doe" class="w-full" />
      </el-form-item>
      <el-form-item label="Email" name="email">
        <el-input v-model="state.email" placeholder="john.doe@example.com" class="w-full" />
      </el-form-item>
      <div class="flex justify-end gap-2">
        <el-button @click="open = false">Cancel</el-button>
        <el-button @click="onSubmit">Create</el-button>
      </div>
    </el-form>
  </el-dialog>
</template>
